package com.thunder.rebot.rebotclient.vam.utils;

import android.text.TextUtils;

import com.thunder.rebot.rebotclient.vam.entity.MapperParams;
import com.thunder.rebot.rebotclient.vam.entity.ViewSize;


public class MapperParamsUtils {
    public static MapperParams getMapperParams(ViewSize actual, int angle, ViewSize screen) {
        if (angle == 90 || angle == 270) {
            actual = new ViewSize(actual.height, actual.width);
        }
        float horizontalRatio = (float) actual.width / screen.width;
        float verticalRatio = (float) actual.height / screen.height;

        float actualScaled = Math.min(horizontalRatio, verticalRatio);
//        float unusedWd = screen.width - (float) actual.width / actualScaled;
//        float unusedHt = screen.height - (float) actual.height / actualScaled;
        float unusedWd = screen.width - (float) actual.width / horizontalRatio;
        float unusedHt = screen.height - (float) actual.height / verticalRatio;
        ViewSize unused = new ViewSize((int) unusedWd, (int) unusedHt);

        float displayRatio = (float) (screen.width - unused.width) / actual.width;
        return new MapperParams(screen, unused, displayRatio);
    }

    /**
     * gets the mapper parameters
     *
     * @param actual actual size
     * @param parent parent mapper params
     * @return mapper params
     */
    public static MapperParams getMapperParams(ViewSize actual, MapperParams parent) {
        float parentTakenWd = parent.screen.width - parent.unused.width;
        float parentTakenHt = parent.screen.height - parent.unused.height;

        float horizontalRatio = (float) actual.width / parentTakenWd;
        float verticalRatio = (float) actual.height / parentTakenHt;
        float actualScaled = Math.max(horizontalRatio, verticalRatio);

        float unusedWd = parentTakenWd - (float) actual.width / actualScaled;
        float unusedHt = parentTakenHt - (float) actual.height / actualScaled;
        ViewSize unused = new ViewSize((int) unusedWd + parent.unused.width, (int) unusedHt + parent.unused.height);

        float displayRatio = (parentTakenWd - unusedWd) / actual.width;
        return new MapperParams(parent.screen, unused, displayRatio);
    }
    
    public static  ViewSize getViewSIze(String resolution){
    	if(TextUtils.equals(resolution, "4K")){
    		return new ViewSize(3840, 2160);
    	}else if (TextUtils.equals(resolution, "1080P")) {
			return new ViewSize(1920, 1080);
		}else if (TextUtils.equals(resolution, "720P")) {
			return new ViewSize(1280, 720);
		}else if (TextUtils.equals(resolution, "480P")) {
			return new ViewSize(640, 480);
		}
    	return new ViewSize(1920, 1080);
    }
}
